package com.realife.ysuper.controller;

import com.realife.common.utils.R;
import com.realife.ysuper.entity.CategoryBrandEntity;
import com.realife.ysuper.service.CategoryBrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;



/**
 * 商品分类和品牌的中间表，两者是多对多关系
 *
 * @author Albert
 * @email 15962463559@163.com
 * @date 2020-06-05 10:04:16
 */
@Slf4j
@RestController
@RequestMapping("/ysuper/categorybrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService;



    /**
     * 信息
     */
    @RequestMapping("/info/{categoryId}")
    //@RequiresPermissions("ysuper:categorybrand:info")
    public R info(@PathVariable("categoryId") Long categoryId){
		CategoryBrandEntity categoryBrand = categoryBrandService.getById(categoryId);

        return R.ok().put("categoryBrand", categoryBrand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ysuper:categorybrand:save")
    public R save(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.save(categoryBrand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ysuper:categorybrand:update")
    public R update(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.updateById(categoryBrand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ysuper:categorybrand:delete")
    public R delete(@RequestBody Long[] categoryIds){
		categoryBrandService.removeByIds(Arrays.asList(categoryIds));

        return R.ok();
    }

}
